package com.javabi.htmlbuilder.html.element.table;

import com.javabi.htmlbuilder.html.HTMLBuilder;
import com.javabi.htmlbuilder.html.HTMLElementList;
import com.javabi.htmlbuilder.html.HTMLElementName;

/**
 * An HTML Table Cell Element.
 * <p>
 * &lt;td&gt; ... &lt;/td&gt;
 * </p>
 */
public class Cell extends HTMLElementList<Cell> {

	/** The rowspan attribute. */
	private int rowspan = 1;
	/** The colspan attribute. */
	private int colspan = 1;

	/**
	 * Returns the rowspan
	 * @return the rowspan
	 */
	public int getRowspan() {
		return rowspan;
	}

	/**
	 * Sets the rowspan
	 * @param rowspan the rowspan to set
	 */
	public void setRowspan(int rowspan) {
		if (rowspan < 1) {
			throw new IllegalArgumentException("rowspan=" + rowspan);
		}
		this.rowspan = rowspan;
	}

	/**
	 * Returns the colspan
	 * @return the colspan
	 */
	public int getColspan() {
		return colspan;
	}

	/**
	 * Sets the colspan
	 * @param colspan the colspan to set
	 */
	public void setColspan(int colspan) {
		if (colspan < 1) {
			throw new IllegalArgumentException("colspan=" + colspan);
		}
		this.colspan = colspan;
	}

	/**
	 * Returns the element name.
	 * @return the element name.
	 */
	public HTMLElementName getElementName() {
		return HTMLElementName.TABLE_DATA;
	}

	/**
	 * Append attributes to the given html builder.
	 * @param html the html builder.
	 * @return the html builder.
	 */
	public HTMLBuilder appendAttributesTo(HTMLBuilder html) {
		if (rowspan > 1) {
			html.attribute("rowspan", rowspan);
		}
		if (colspan > 1) {
			html.attribute("colspan", colspan);
		}
		return html;
	}

}
